<template>
  <el-dialog v-if="load" title="变更日志" v-model="visible" append-to-body :close-on-click-modal="false" :z-index="2000" width="800px" @close="handleClose">
    <vxe-table :data="data" :loading="loading">
      <vxe-column title="变更人员" field="create_user" min-width="120"></vxe-column>
      <vxe-column title="变更时间" field="create_time" min-width="120"></vxe-column>
      <template v-if="form.change_type === 1">
        <vxe-column title="原始预计到货时间" field="origin_expect_delivery_time" width="140"></vxe-column>
        <vxe-column title="变更预计到货时间" field="expect_delivery_time" width="140"></vxe-column>
      </template>
      <template v-else>
        <vxe-column title="变更前工厂可交货时间" field="origin_expect_delivery_time" width="140"></vxe-column>
        <vxe-column title="变更后工厂可交货时间" field="expect_delivery_time" width="140"></vxe-column>
      </template>
      <vxe-column title="变更原因" field="change_reason_name" width="120">
        <template #default="{row}">
          <VText :value="row.change_reason_name" />
        </template>
      </vxe-column>
      <vxe-column title="变更备注" field="change_remark" width="120">
        <template #default="{row}">
          <VText :value="row.change_remark" />
        </template>
      </vxe-column>
    </vxe-table>
    <template #footer>
      <el-button @click="close">关 闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import api from '../api'

const props = defineProps({
  options: { type: Object, default: () => ({}) },
})
const emit = defineEmits(['close', 'success'])

const load = ref(false)
const visible = ref(false)
let loading = ref(false)
const data = ref([])
const form = ref({})

// 打开弹窗
const open = async (params) => {
  if (!load.value) {
    load.value = true
    await 1
  }
  form.value = params
  data.value = []
  visible.value = true
  loading.value = true
  api.deliverTimeRecord(form.value).then(res => {
    data.value = res.data
  }).finally(() => {
    loading.value = false
  })
}
// 关闭弹窗
const close = () => {
  visible.value = false
}

const handleClose = () => {
  emit('close')
}

defineExpose({ open })
</script>